<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%
    String path = request.getContextPath();
%>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="<%=path%>/plugins/layui/css/layui.css?version=1">
    <script src="<%=path %>/plugins/jquery.min.js" type="text/javascript"></script>
    <script src="<%=path%>/plugins/layui/layui.js"></script>
</head>
<body>
<form id="form" class="layui-form" method="post" key="set-mine" action="">
    <input id="resource_id" name="resource_id" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">分类标签</label>
        <div class="layui-input-block">
            <select id="type_code" name="type_code">
                <option value="">请选择</option>
                <c:forEach items="${types}" var="item">
                    <option value="${item.type_code}">${item.type_name}</option>
                </c:forEach>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input name="title" lay-verify="required" autocomplete="off" placeholder="请输入标题" class="layui-input"
                   type="text">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <input name="description" lay-verify="required" autocomplete="off" placeholder="请输入描述" class="layui-input"
                   type="text">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">图标链接</label>
        <div class="layui-input-block">
            <input type="hidden" id="icon_url" name="icon_url">
            <input id="icon_url_display" name="icon_url_display" lay-verify="url" autocomplete="off"
                   placeholder="http://" class="layui-input" type="tel">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-block">
            <div class="layui-box layui-upload-button">
                <input name="file" class="layui-upload-file" type="file">
            </div>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">内容链接</label>
        <div class="layui-input-block">
            <input name="content_url" lay-verify="url" autocomplete="off" placeholder="http://" class="layui-input"
                   type="tel">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="savebt" id="savebt" type="submit">保存</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script>
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    layui.use(['layer', 'form', 'upload'], function () {
        var form = layui.form()
            , layer = layui.layer
        //监听提交
        form.on('submit(savebt)', function (data) {
            postJson("<%=path%>/cms/resource/saveResource.x", $.param(data.field), function (ret) {
                var param = {};
                param.pageSize = parent.modelParam.pageSize;
                param.page = 1;
                parent.queryPage(param);
                layer.alert('操作成功！', {icon: 6});
                parent.layer.close(index);
            });
            return false;
        });


        layui.upload({
            url: '<%=path%>/cms/resource/uploadFile.x'
            , success: function (res, input) {
                console.log(res);
                console.log(input);
                $('#icon_url').val(res.data.imagePath);
                $('#icon_url_display').val(res.data.imageUrl);
            }
        });
    });
    $(document).ready(function () {
        var options = {jsonValue: '${resource}'};
        $('#form').initForm(options);
    });


    //在父层弹出一个层
    $('#new').on('click', function () {
        parent.layer.msg('Hi, man', {shade: 0.3})
    });
    //给父页面传值
    $('#transmit').on('click', function () {
        parent.$('#parentIframe').text('我被改变了');
        parent.layer.tips('Look here', '#parentIframe', {time: 5000});
        parent.layer.close(index);
    });
    //关闭iframe
    $('#closeIframe').click(function () {
        var val = $('#name').val();
        if (val === '') {
            parent.layer.msg('请填写标记');
            return;
        }
        parent.layer.msg('您将标记 [ ' + val + ' ] 成功传送给了父窗口');
        parent.layer.close(index);
    });
</script>

<script type="text/javascript" src="<%=path%>/js/core/helper.js"></script>
</body>
</html>
